package com.leilei.view;

import com.google.gson.Gson;
import com.leilei.dao.ICommodityDao;
import com.leilei.dao.ICommodityVersion;
import com.leilei.dao.IHisShoppingCustomDao;
import com.leilei.dao.impl.CommodityDaoImpl;
import com.leilei.dao.impl.HisShoppingCustomDaoImpl;
import com.leilei.dao.impl.UserServiceImpl;
import com.leilei.entity.*;
import com.leilei.service.ICommodityService;
import com.leilei.service.IUserService;
import com.leilei.service.impl.CommodityServiceImpl;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class testPhone {

    public static void main(String[] args) {

        ICommodityService phoneService = new CommodityServiceImpl();

        List<Commodity> list = phoneService.getCommodityInIndex(1);

        for (Commodity commodity : list) {
            System.out.println(commodity);
        }

    }

    @Test
    public void testCommodity(){

        ICommodityDao commodityDao = new CommodityDaoImpl();
        Commodity commodity = commodityDao.selectCommodityCustom(1, 1, 1);

        System.out.println(commodity);
    }

    @Test
    public void test03(){

        IHisShoppingCustomDao hisShoppingCustomDao = new HisShoppingCustomDaoImpl();

        List<HisShoppingCustom> hisShoppingCustoms = hisShoppingCustomDao.selectUserHisShoppingCustom(5);

        System.out.println(hisShoppingCustoms);
    }

    @Test
    public void testCommodityCustom(){

        ICommodityService phoneService = new CommodityServiceImpl();

        Commodity commodity = phoneService.getCommodityCustom(1, 1, 1);

        System.out.println(commodity);
    }

    @Test
    public void testUser(){

        ICommodityService commodityService = new CommodityServiceImpl();
        Commodity commodityCustom = commodityService.getCommodityCustom(3, 10, 9);
        System.out.println(commodityCustom);

    }

    @Test
    public void testSaveUser(){

        User user = new User();
        user.setName("大果粒");
        user.setUsername("kl281015");
        user.setPassword("123123");
        user.setAddress("陕西省西安市大明宫北街道");
        user.setRegisterDate(new Date());

        List<Address> list = new ArrayList<>();
        Address address = new Address();
        address.setAddress("陕西省西安市大明宫北街道");
        address.setTel("13051658698");
        list.add(address);
        user.setAddressList(list);

        IUserService userService = new UserServiceImpl();
        userService.saveUser(user);

    }


    @Test
    public void test02(){

        //获取到要购买的商品的id
        String spid = "4999.0";

        double pid = spid == null ? 0 : Double.parseDouble(spid);
        System.out.println(pid);
    }

    @Test
    public void test04() throws Exception {
        //List集合转为json
        List<ShoppingCustom> list = new ArrayList<>();
        ShoppingCustom s1 = new ShoppingCustom();
        s1.setPid(1);
        s1.setPvid(1);
        s1.setPcid(1);
        ShoppingCustom s2 = new ShoppingCustom();
        s2.setPid(2);
        s2.setPvid(2);
        s2.setPcid(2);

        list.add(s1);
        list.add(s2);
        Gson gson = new Gson();
        System.out.println(gson.toJson(list));
    }
}
